/*
 * @Description: 菜单权限
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2024-03-21
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-05-20
 */

import { requestGetPermissionByCompanyId } from '/@/api/system/ysys-user/permission'
import { RouterPathEnum } from '/@/enums/routerEnum'
import router from '/@/router'
import { checkWhiteRoute } from '/@/router'
import { getCompanyInfo } from '/@/storage'
import { useMenu } from '/@/store/modules/menu'

/**
 * 查询权限菜单
 */
export const setupMenu = async () => {
  const menu = useMenu()
  const { companyId } = getCompanyInfo()
  const { responseData } = await requestGetPermissionByCompanyId({ companyId })
  if (responseData) {
    menu.setMenus(responseData[0]?.menu)
  } else {
    menu.setMenus([])
    if (!checkWhiteRoute()) router.replace(RouterPathEnum.HOME)
  }
}
